<?php

use yii\helpers\Html;
//use yii\bootstrap\ActiveForm;
use kartik\widgets\ActiveForm;

use \dmstr\bootstrap\Tabs;
use yii\helpers\StringHelper;
use kartik\widgets\FileInput;
use yii\helpers\Url;
use kartik\daterange\DateRangePicker;
use kartik\widgets\DatePicker;
use kartik\widgets\DateTimePicker;
use kartik\widgets\TouchSpin;
use kartik\widgets\Select2;
use kartik\label\LabelInPlace;
use kartik\widgets\TypeaheadBasic;
use kartik\widgets\Growl;
use kartik\ipinfo\IpInfo;
use kartik\popover\PopoverX;
use kartik\checkbox\CheckboxX;
use kartik\widgets\StarRating;
use kartik\number\NumberControl;
use kartik\icons\FontAwesomeAsset;

FontAwesomeAsset::register($this);

/**
 * @var yii\web\View $this
 * @var common\models\demo $model
 * @var yii\widgets\ActiveForm $form
 */
$data = [
    "red" => "red",
    "green" => "green",
    "blue" => "blue",
    "orange" => "orange",
    "white" => "white",
    "black" => "black",
    "purple" => "purple",
    "cyan" => "cyan",
    "teal" => "teal"
];
?>

<div class="demo-form">

    <?php $form = ActiveForm::begin([
            'id' => 'demo',
            'type' => ActiveForm::TYPE_HORIZONTAL,
            // 'layout' => 'horizontal',
            'enableClientValidation' => true,
            'errorSummaryCssClass' => 'error-summary alert alert-danger',
            'fieldConfig' => [
                'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
                'horizontalCssClasses' => [
                    'label' => 'col-sm-2',
                    #'offset' => 'col-sm-offset-4',
                    'wrapper' => 'col-sm-8',
                    'error' => '',
                    'hint' => '',
                ],
            ],
        ]
    );
    ?>

    <div class="">
        <?php $this->beginBlock('main'); ?>

        <p>


            <!-- attribute password -->
            <?= $form->field($model, 'password')->passwordInput(['maxlength' => true]) ?>

            <!-- attribute password_repeat -->
            <?= $form->field($model, 'password_repeat')->textInput(['maxlength' => true]) ?>

            <!-- attribute date -->

            <?php

            echo $form->field($model, 'date')->widget(DatePicker::class, [

                'options' => [
                    'placeholder' => 'Enter birth date ...',
                ],
                'pluginOptions' => [
                    'todayHighlight' => true,
                    'todayBtn' => true,
                   'format' => 'yyyy-mm-dd',
                    'autoclose' => true
                ]
            ]);

            ?>

            <!-- attribute date_time -->

            <?php

            echo $form->field($model, 'date_time')->widget(DateTimePicker::class, [
                'options' => ['placeholder' => 'Enter event time ...'],
                'pluginOptions' => [
                    'autoclose' => true
                ]
            ]);

            ?>

            <!-- attribute double_value -->


            <?php

            echo $form->field($model, 'double_value', [
                'addon' => [
                    'prepend' => ['content' => '$', 'options' => ['class' => 'alert-success']],

                    'append' => ['content' => '.00']],
            ])->label('价格');
            ?>
            <!-- attribute email -->

            <?php echo $form->field($model, 'email', [
                'addon' => ['prepend' => ['content' => '@']]
            ]); ?>
            <!-- attribute ip -->

            <?php echo $form->field($model, 'ip', [
                'addon' => ['prepend' => ['content' => '@']]
            ]); ?>
            <?php
//            echo IpInfo::widget([
//                'ip' => Yii::$app->request->userIP,
//                'popoverOptions' => [
//                    'toggleButton' => ['class' => 'btn btn-secondary btn-lg'],
//                    'placement' => PopoverX::ALIGN_BOTTOM_LEFT
//                ]
//            ]);
            ?>

            <!-- attribute age -->
            <?= $form->field($model, 'age')->textInput() ?>

            <!-- attribute number -->
            <?php

            echo $form->field($model, 'number')->widget(\kartik\number\NumberControl::class,[
                    'maskedInputOptions'=>[
                        'digits' => 5,
                      //  'groupSeparator' => '.',
                        'radixPoint' => '.'

                    ]

            ]);

//            echo NumberControl::widget([
//                'name' => 'number',
//                'value' => 1000,
//                'maskedInputOptions' => [
////                    'prefix' => '$ ',
////                    'suffix' => ' €',
//                    'digits' => 4
//                ],
               // 'options' => $saveOptions,
              //  'displayOptions' => $dispOptions,
               // 'saveInputContainer' => $saveCont
          //  ]);
            ?>

            <!-- attribute url -->
            <?= $form->field($model, 'url')->textInput(['maxlength' => true]) ?>

            <!-- attribute content -->
            <?= $form->field($model, 'content')->textarea(['rows' => 6]) ?>

            <!-- attribute json_value -->


            <!-- attribute zip_code -->
            <?= $form->field($model, 'zip_code')->textInput(['maxlength' => true]) ?>

            <!-- attribute address -->
            <?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>

            <!-- attribute mobile -->

            <?php
            echo $form->field($model, 'mobile', [
                'addon' => ['prepend' => ['content' => '<i class="glyphicon glyphicon-phone"></i>']]
            ]);
            ?>

            <!-- attribute chinese_string -->

            <?php
//            echo $form->field($model, 'chinese_string')->widget(Select2::class, [
//                'data' => $data,
//                'options' => ['placeholder' => 'Select a color ...', 'multiple' => true],
//                'pluginOptions' => [
//                    'tags' => true,
//                    'tokenSeparators' => [',', ' '],
//                    'maximumInputLength' => 10
//                ],
//            ]);
            // ->label('Tag Multiple');
            ?>

            <!-- attribute image -->

            <?php

            echo $form->field($model, 'image')->widget(FileInput::class, [

                'options'=>[
                    'multiple'=>false,
                    'accept' => 'image/*',
                    'showDrag'=>false,
                    //'data-num'=>$count,

                ],
                'pluginOptions' => [
                   'initialPreview'=>\yii\helpers\Json::decode($model->image)??[],
                    'showPreview'=>true,
                    'initialPreviewAsData'=>true,
                    'dropZoneTitle'=>'',
                  //  'initialPreviewConfig' => $del,
                    'overwriteInitial'=>false,
                    'uploadUrl' => Url::to(['demo/upload2']),
                    'data-num'=>444,
                    'uploadAsync'=> true,
//                    'uploadExtraData' => [
//                        'product_id' => $goods['product_id'],
//                        'order_no'=>$goods['order_no'],
//                    ],
                    'minFileCount'=>1,
                    'maxFileCount' => 10,
                    'maxFileSize'=>2000,
//                    'initialPreviewConfig' => [
//                        ['caption' => 'Moon.jpg', 'size' => '873727'],
//                        ['caption' => 'Earth.jpg', 'size' => '1287883'],
//                    ],

                    'mainClass'  => 'input-group-sm',
                    'showRemove' => false,
                    'showUpload' => true,
                    'showCancel' => false,
                    'showClose'  => false,
                    'fileActionSettings' => ['showDrag'=>false],


                ],

                'pluginEvents'  =>  [
                    'filebatchselected' =>  "function(event,id){
                                                                            $(this).fileinput('upload');
                                                                         }",
                    'fileuploaded'=>"   function(event, data, previewId, index) {
                  
                                                                    $(\"[name='\" +event.currentTarget.attributes[1].ownerElement.name+ \"']\" ).first().val(JSON.stringify(data.response.initialPreviewConfig));
                                                                } ",
                ]
            ]);

            ?>


            <!-- attribute file -->


            <?php

            echo $form->field($model, 'file')->widget(FileInput::class, [

                'options'=>[
                    'multiple'=>false,
                    'accept' => 'image/*',
                    'showDrag'=>false,
                    //'data-num'=>$count,

                ],
                'pluginOptions' => [
                 //   'initialPreview'=>\yii\helpers\Json::decode($model->file)??[],
                    'showPreview'=>true,
                    'initialPreviewAsData'=>true,
                    'dropZoneTitle'=>'',
                    //  'initialPreviewConfig' => $del,
                    'overwriteInitial'=>false,
                    'uploadUrl' => Url::to(['demo/upload2']),
                    'data-num'=>444,
                    'uploadAsync'=> true,
//                    'uploadExtraData' => [
//                        'product_id' => $goods['product_id'],
//                        'order_no'=>$goods['order_no'],
//                    ],
                    'minFileCount'=>1,
                    'maxFileCount' => 10,
                    'maxFileSize'=>2000,
//                    'initialPreviewConfig' => [
//                        ['caption' => 'Moon.jpg', 'size' => '873727'],
//                        ['caption' => 'Earth.jpg', 'size' => '1287883'],
//                    ],

                    'mainClass'  => 'input-group-sm',
                    'showRemove' => false,
                    'showUpload' => true,
                    'showCancel' => false,
                    'showClose'  => false,
                    'fileActionSettings' => ['showDrag'=>false],


                ],

                'pluginEvents'  =>  [
                    'filebatchselected' =>  "function(event,id){
                                                                            $(this).fileinput('upload');
                                                                         }",
                    'fileuploaded'=>"   function(event, data, previewId, index) {
                  
                                                                    $(\"[name='\" +event.currentTarget.attributes[1].ownerElement.name+ \"']\" ).first().val(JSON.stringify(data.response.initialPreviewConfig));
                                                                } ",
                ]
            ]);

            ?>


            <?php
//            echo $form->field($model, 'file[]')->widget(FileInput::class, [
//                'options' => ['accept' => 'image/*'],
//            ]);

            ?>
            <!-- attribute title -->
            <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>

            <!-- attribute slug -->
            <?= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?>

            <!-- attribute boolean -->
            <?php echo $form->field($model, 'boolean', [
                'template' => '{input}{label}{error}{hint}',
                'labelOptions' => ['class' => 'cbx-label']
            ])->widget(CheckboxX::class, ['autoLabel' => false]);
            ?>


            <!-- attribute data_time -->

            <!-- attribute data -->
        </p>
        <?php $this->endBlock(); ?>

        <?=
        Tabs::widget(
            [
                'encodeLabels' => false,
                'items' => [
                    [
                        'label' => Yii::t('models', 'demo'),
                        'content' => $this->blocks['main'],
                        'active' => true,
                    ],
                ]
            ]
        );
        ?>
        <hr/>

        <?php echo $form->errorSummary($model); ?>

        <?= Html::submitButton(
            '<span class="glyphicon glyphicon-check"></span> ' .
            ($model->isNewRecord ? Yii::t('cruds', 'Create') : Yii::t('cruds', 'Save')),
            [
                'id' => 'save-' . $model->formName(),
                'class' => 'btn btn-success'
            ]
        );
        ?>

        <?php ActiveForm::end(); ?>

    </div>

</div>
<?php


echo Growl::widget([
    'type' => Growl::TYPE_SUCCESS,
    'title' => 'Well done!',
    'icon' => 'glyphicon glyphicon-ok-sign',
    'body' => 'You successfully read this important alert message.',
    'showSeparator' => true,
    'delay' => 0,
    'pluginOptions' => [

        'showProgressbar' => true,
        'placement' => [
            'from' => 'top',
            'align' => 'right',
        ]
    ]
]);
echo Growl::widget([
    'type' => Growl::TYPE_INFO,
    'title' => 'Heads up!',
    'icon' => 'glyphicon glyphicon-info-sign',
    'body' => 'This alert needs your attention, but it\'s not super important.',
    'showSeparator' => true,
    'delay' => 1500,
    'pluginOptions' => [
        'showProgressbar' => true,
        'placement' => [
            'from' => 'top',
            'align' => 'right',
        ]
    ]
]);
echo Growl::widget([
    'type' => Growl::TYPE_WARNING,
    'title' => 'Warning!',
    'icon' => 'glyphicon glyphicon-exclamation-sign',
    'body' => 'Better check yourself, you\'re not looking too good.',
    'showSeparator' => true,
    'delay' => 3000,
    'pluginOptions' => [
        'delay' => 0,
        'showProgressbar' => true,
        'placement' => [
            'from' => 'top',
            'align' => 'right',
        ]
    ]
]);
echo Growl::widget([
    'type' => Growl::TYPE_DANGER,
    'title' => 'Oh snap!',
    'icon' => 'glyphicon glyphicon-remove-sign',
    'body' => 'Change a few things up and try submitting again.',
    'showSeparator' => true,
    'delay' => 4500,
    'pluginOptions' => [
        'showProgressbar' => true,
        'placement' => [
            'from' => 'top',
            'align' => 'right',
        ]
    ]
]);
echo Growl::widget([
    'type' => Growl::TYPE_GROWL,
    'title' => 'Roar!',
    //'icon' => '/images/growl_64x.png',
    'body' => 'This is a default growling alert you requested for.',
    'showSeparator' => false,
    'delay' => 6000,
    'pluginOptions' => [
        'icon_type' => 'image',
        'showProgressbar' => false,
        'placement' => [
            'from' => 'top',
            'align' => 'right',
        ],
    ]
]);
echo Growl::widget([
    'type' => Growl::TYPE_MINIMALIST,
    'title' => 'Kartik Visweswaran',
   // 'icon' => '/images/kartik.png',
    'iconOptions' => ['class' => 'img-circle pull-left'],
    'body' => 'Momentum reduce child mortality effectiveness incubation empowerment connect.',
    'showSeparator' => false,
    'delay' => 7500,
    'pluginOptions' => [
        'icon_type' => 'image',
        'showProgressbar' => false,
        'placement' => [
            'from' => 'top',
            'align' => 'right',
        ],
    ]
]);
echo Growl::widget([
    'type' => Growl::TYPE_PASTEL,
    'title' => 'Email: Erica Fisher',
    //'icon' => '/images/growl_64x.png',
    'body' => 'Investment, stakeholders micro-finance equity health Bloomberg; global citizens climate change. ' .
        'Solve positive social change sanitation, opportunity insurmountable challenges...',
    'showSeparator' => false,
    'delay' => 9000,
    'progressBarOptions' => ['class' => 'progress-bar-warning'],
    'pluginOptions' => [
        'showProgressbar' => true,
        'icon_type' => 'image',
        'placement' => [
            'from' => 'top',
            'align' => 'right',
        ],
    ]
]);
?>
